import express from "express";
import { formatRequestQuery, formatResponse } from "../../utils/tools";
import { SysDictTypeService } from "../../services/system/SysDictTypeService";
const router = express.Router();

router.post("/", async (req, res) => {
  await SysDictTypeService.add(req.body);
  res.send(formatResponse<null>(null, "操作成功"));
});

router.delete("/:id", async (req, res) => {
  const result = await SysDictTypeService.delete(req.params.id);
  res.send(formatResponse(result));
});

router.put("/", async (req, res) => {
  const result = await SysDictTypeService.update(req.body);
  res.send(formatResponse(result));
});

router.get("/page", async (req, res) => {
  const { query, other } = formatRequestQuery(req.query, ["dictName", "dictType"]);
  const result = await SysDictTypeService.findByPage(query.current, query.size, other);
  res.send(formatResponse<typeof result>(result));
});

/**
 * 下拉选择
 */
router.get("/optionSelect/:dictType", async (req, res) => {
  const result = await SysDictTypeService.findOptionSelect(req.params.dictType);
  res.send(formatResponse<typeof result>(result));
});

router.get("/:id", async (req, res) => {
  const result = await SysDictTypeService.findById(req.params.id);
  res.send(formatResponse(result));
});

export default router;
